//
//  AppDelegate.m
//  Bees
//
//  Created by Xiaohan on 2018/12/3.
//  Copyright © 2018 xiaohan. All rights reserved.
//

#import "AppDelegate.h"
#import "AppDelegate+NTESService.h"
#import "ValidationSafetyCodeViewController.h"
#import "AppDelegate+NotiPush.h"
#import "AppDelegate+UMengHelper.h"
#import "ScatterDappManager.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    DLog(@"hello");
    [self initWindow];
    [self initService];
    [self setupNIMSDK];
    [self registerForRemoteNotifications:launchOptions];
    [self initUserManager];
    [self UMSocialStart];
    if (IS_DIDSET_LOCAl_Application_Key) {
        [ValidationSafetyCodeViewController showValidation];
    }
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    DLog(@"%s",__func__);
  
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    DLog(@"%s",__func__);
    if (kIsNeedBackgroundLockApplication && IS_DIDSET_LOCAl_Application_Key) {
        [ValidationSafetyCodeViewController showValidation];
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    DLog(@"%s",__func__);
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    DLog(@"%s",__func__);
    if (IS_DIDSET_LOCAl_Application_Key && [ValidationSafetyCodeViewController isShow]) {
//        [WalletTool sharedWalletTool].onceOpenApp = YES;
//        [ValidationSafetyCodeViewController showValidation];
        [ValidationSafetyCodeViewController check];
    }
}


- (void)applicationWillTerminate:(UIApplication *)application {
    
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { 
    if ([[url absoluteString]hasPrefix:kWechatKey]) {
        ///微信分享回调
        return  [[UMSocialManager defaultManager] handleOpenURL:url options:options];;
    }else if([[url absoluteString]hasPrefix:kBeesgameScheme]){
        DLog(@"打开DAPP");
        DLog(@" url %@",url);
        DLog(@"options %@",options);
        [ScatterDappManager jumpforDapp:[FoundRecommendModel new]];
    }
    
    return YES;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[[NIMSDK sharedSDK] loginManager] removeDelegate:self];
}
@end
